package com.juc.callable.callable3;

import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;
import java.util.concurrent.LinkedBlockingDeque;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

public class Run {

	/**
	 * submit(Runnable task, T result)
	 * 第二个参数result可以作为执行结果的返回值 而不需要使用get()方法获得
	 * @param args
	 * @throws InterruptedException
	 * @throws ExecutionException
	 */
	public static void main(String[] args) throws InterruptedException, ExecutionException {
		Userinfo userinfo = new Userinfo();
		MyRunnable myRunnable = new MyRunnable(userinfo);
		ThreadPoolExecutor executor = new ThreadPoolExecutor(10, 10, 10, TimeUnit.SECONDS, new LinkedBlockingDeque<Runnable>());
		Future<Userinfo> future = executor.submit(myRunnable,userinfo);
		System.out.println("begin time = " + System.currentTimeMillis());
		future.get();
		System.out.println("get Value = " + userinfo.getUsername() + "  " + userinfo.getPassword());
		System.out.println("end time = " + System.currentTimeMillis());

	}
}
